package rocketman;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;
import java.awt.Toolkit;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class BulletTargetted extends Bullet
{
protected int counter = 0;
protected int playerx, playery;
protected double bulletspeed = 1;
public BulletTargetted(int startx, int starty, String filename, int px, int py, double bulletspd)
{
	super(startx, starty, filename);
	
	bulletspeed = bulletspd;

	playerx = px;
	playery = py;

	if (playerx == 0)
		playerx = 1;
	if (playery == 0)
		playery = 1;

	double ricox,ricoy;
	ricox = (double)Math.abs(playerx-getx());
	ricoy = (double)Math.abs(playery-gety());

	if (playerx <= getx() && playery <= gety()) {
		dx2 = - Math.abs(playerx-getx())/(ricox/ricoy);
		dy2 = - Math.abs(playery-gety())/(ricox/ricoy);
	}
	else if (playerx >= getx() && playery <= gety()) {
		dx2 =   Math.abs(playerx-getx())/(ricox/ricoy);
		dy2 = - Math.abs(playery-gety())/(ricox/ricoy);
	}
	else if (playerx <= getx() && playery >= gety()) {
		dx2 = - Math.abs(playerx-getx())/(ricox/ricoy);
		dy2 =   Math.abs(playery-gety())/(ricox/ricoy);
	}
	else if (playerx >= getx() && playery >= gety()) {
		dx2 =   Math.abs(playerx-getx())/(ricox/ricoy);
		dy2 =   Math.abs(playery-gety())/(ricox/ricoy);
	}
	dx2 *= (double)(bulletspeed/distance(playerx,getx(),playery,gety()));
	dy2 *= (double)(bulletspeed/distance(playerx,getx(),playery,gety()));
}

public void  move()
{
	counter += 1;
	//if (counter == bulletspeed) 
	{
		counter = 0;
		if (dx2 != 0) {
			x += (int)(dx2/*-bulletspeed*/);
		}
		if (dy2 != 0) {
			y += (int)(dy2/*-bulletspeed*/);
		}
	}
}

};


